<?php
Class CNVDAO
{
	public $connexion;

	public function __construct()
	{
		try {
			$this->connexion = new PDO("mysql:host=".SERVEUR_MYSQL.";dbname=".BASE.";charset=utf8", UTILISATEUR, M2P);
			$this->connexion_base_hg = new PDO("mysql:host=".SERVEUR_MYSQL.";dbname=".BASE_HG.";charset=utf8", UTILISATEUR, M2P);
		}
		catch(PDOException $e)
		{
			echo "Erreur : ".$e->getMessage();
			die("Mot de passe ou Identifiant incorrect");
		}
	}
	
	public function recuperer_version_hg_par_idCNV($idCNV){
		$req = "SELECT p.versionhg FROM puce as p, cnv_hg18 as c WHERE c.idpuce = p.idpuce and c.idcnv = :idcnv";
		$requette_preparee = $this->connexion->prepare($req);
		$requette_preparee->bindValue(":idcnv" , $idCNV, PDO::PARAM_INT);
		$result = $requette_preparee->execute();
		if ($result == 1){
			$req2 = "SELECT p.versionhg FROM puce as p, cnv_hg19 as c WHERE c.idpuce = p.idpuce and c.idcnv = :idcnv";
			$requette_preparee2 = $this->connexion->prepare($req2);
			$requette_preparee2->bindValue(":idcnv" , $idCNV, PDO::PARAM_INT);
			$result2 = $requette_preparee2->execute();
			$version = $requette_preparee2->fetchColumn(0);
		}else {
			$version = $requette_preparee->fetchColumn(0);
		}
		return substr($version,2,2);
	}
	public function recuperer_version_hg_par_idPuce($idPuce){
		$req = "SELECT p.versionhg FROM puce as p WHERE  p.idpuce  = :idpuce";
		$requette_preparee = $this->connexion->prepare($req);
		$requette_preparee->bindValue(":idpuce" , $idPuce, PDO::PARAM_INT);
		$result = $requette_preparee->execute();
		$version =  $requette_preparee->fetchcolumn(0);
		return substr($version,2,2);
	}
	

	// recuperer_cytobande_par_cnv
	public function recuperer_cyto_par_idCNV($idCNV)
	{
		$cyt="";
		$ReqAttri = "SELECT a.attribute_value, b.tag FROM base_hg.hg18_attribute AS a, base_hg.hg18_attributelist AS b WHERE b.tag like 'Cytoband' AND a.attribute_id = b.id and a.id = :idCNV";
		$requette_preparee = $this->connexion_base_hg->prepare($ReqAttri);
		$requette_preparee->bindValue(":idCNV" , $idCNV, PDO::PARAM_INT);
		if ($requette_preparee->execute()){
			while($row2 = $requette_preparee->fetchObject()) {
				if ($row2->tag == 'Cytoband'){
					$Cytob = $row2->attribute_value;
				}
			}
			$arrayCyto = explode(',',$row2->attribute_value, -1);
			$taille_tab = count($arrayCyto);

			for($i=0; $i<$taille_tab; $i++){
				$cyt .= $arrayCyto[$i];
				if($i+1 < $taille_tab) $cyt .= ", ";
			}

		}else{
			$taberr = $requette_preparee->errorInfo();
			$cyt = "Erreur numéro :".$taberr[0]."(".$taberr[1].")";
		}
		return $cyt;
	}

	// recuperer_interval_hg19_correspond_hg18_par_cnv
	public function recuperer_INTER_par_idCNV($idCNV, $versionhg)
	{
		$id_cnv = $idCNV;

		// Requête permettant de récupérer les coordonnées du cnv en version HG19
		$ReqCoordHg19 = "SELECT start, end FROM base_hg.hg".$versionhg."_feature WHERE id = :idCNV";
		$requette_preparee = $this->connexion_base_hg->prepare($ReqCoordHg19);
		$requette_preparee->bindValue(":idCNV" , $id_cnv, PDO::PARAM_INT);
		$requette_preparee->execute();
		$row3 = $requette_preparee->fetchObject();
		return $row3;
	}


	public function recuperer_CNV_par_puce($idpuce)
	{
		$query = "SELECT  idpuce, idcnv, positiondebut, positionfin, chromosome, sondedebut, sondefin, log2ratio, nbcopie ,verifie, methodeverification, herite, commentaire, classification "
				." FROM cnv_hg".$this->recuperer_version_hg_par_idPuce($idpuce);
		$query .=" WHERE 1 ";
		if ($idpuce != null && $idpuce != 0){
			$query .= " AND idpuce = :idpuce";
		}
		$requette_preparee = $this->connexion->prepare($query);
		if ($idpuce != null){
			$requette_preparee->bindValue(":idpuce" , $idpuce, PDO::PARAM_INT);
		}
		$requette_preparee->execute();
		$cnv = $requette_preparee->fetchAll(PDO::FETCH_CLASS,'CNV');
		return  $cnv;

	} // recuperer_CNV_par_puce

	public function recuperer_CNV_par_idCNV($idCNV)
	{
		$query = "SELECT  idpuce, idcnv, positiondebut, positionfin, chromosome, sondedebut, sondefin, log2ratio, nbcopie ,verifie, methodeverification, herite, commentaire, classification "
				." FROM cnv_hg".$this->recuperer_version_hg_par_idCNV($idCNV);
		$query .=" WHERE 1 ";
		if ($idCNV != null && $idCNV != 0){
			$query .= " AND idcnv = :idcnv";
		}
		$requette_preparee = $this->connexion->prepare($query);
		if ($idCNV != null && $idCNV != 0){
			$requette_preparee->bindValue(":idcnv" , $idCNV, PDO::PARAM_INT);
		}
		$requette_preparee->execute();
		return  $requette_preparee->fetchObject('CNV');;

	} // recuperer_CNV_par_idCNV

	////////////////////////////////////////////
	public function ajouter_cnv($cnv)
	{
		$message = "";
		////////////////////////////////////////////
		$ctrl=-1;
		$puce = $cnv->idpuce;
		$baseB  = $cnv->positiondebut;
		$baseH  = $cnv->positionfin;
		$chro = $cnv->chromosome;

		$rqt3 = "SELECT p.iddossier, p.versionhg, d.sexe FROM puce as p, dossier as d
				WHERE p.iddossier = d.iddossier AND p.idpuce = :idpuce";
		$requette_preparee0 = $this->connexion->prepare($rqt3);
		$requette_preparee0->bindValue(":idpuce" , $cnv->idpuce, PDO::PARAM_INT);
		$requette_preparee0->execute();
		$obj = $requette_preparee0->fetchObject();
		$iddossier = $obj->iddossier;
		$Genome = $obj->versionhg;
		$sexe = $obj->sexe;

		if ($cnv->sondedebut != null){
			$sondedebut = $cnv->sondedebut;
		}
		else{
			$sondedebut = 0;
		}
		if ($cnv->sondefin != null){
			$sondefin = $cnv->sondefin;
		}
		else{
			$sondefin = 0;
		}
		if ($cnv->log2ratio != null){
			$log2ratio = $cnv->log2ratio ;
		}
		else{
			$log2ratio = "''";
		}

		
		if ($cnv->nbcopie == null || $cnv->nbcopie == ""){
			$cnv->nbcopie = $this->convert_log2R_nb_copie($cnv->log2ratio,$cnv->chromosome, $sexe);
		}
		$nbcopie = $cnv->nbcopie;

		if ($cnv->classification  != null){
			$classification = $cnv->classification ;
		}
		else{
			$classification = "''";
		}
		if ($cnv->methodeverification != null){
			$methodeverification = $cnv->methodeverification;
		}
		else{
			$methodeverification = "0";
		}
		if ($cnv->verifie != null){
			$verifie = $cnv->verifie ;
		}
		else{
			$verifie = "1";
		}
		
		
		if ($cnv->commentaire != null){
			$commentaire = $cnv->commentaire ;
		}
		else{
			$commentaire = "''";
		}
		if ($cnv->herite != null){
			$herite = $cnv->herite ;
		}
		else{
			$herite = "1";
		}

		//conversion HG18<->HG19
		////////////////////////////////////////////////////////////////////////////////////////////////////
		if ($Genome == 'hg18') {
			$GenomeConvert = 'hg19';
			$convertBaseB = exec("perl script_perl/liftover.pl chr$chro $baseB script_perl/hg18ToHg19.over.chain ; echo $?");
			$convertBaseH = exec("perl script_perl/liftover.pl chr$chro $baseH script_perl/hg18ToHg19.over.chain ; echo $?");
		}else{
			$GenomeConvert = 'hg18';
			$convertBaseB = exec("perl script_perl/liftover.pl chr$chro $baseB script_perl/hg19ToHg18.over.chain ; echo $?");
			$convertBaseH = exec("perl script_perl/liftover.pl chr$chro $baseH script_perl/hg19ToHg18.over.chain ; echo $?");
		}
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		$convertBaseB=substr($convertBaseB, 0, -1);
		$convertBaseH=substr($convertBaseH, 0, -1);
		//insertion dans la base GBrowse
		if (($convertBaseB != -1) && ($convertBaseH != -1 )){
			if ($Genome == 'hg18') {
				$retour = exec("perl script_perl/script_insertion_cnv.pl $iddossier $puce $chro $baseB $baseH $nbcopie $log2ratio $Genome $sondedebut $sondefin $verifie $methodeverification $herite \"$commentaire\" $classification -1 ; echo $?");
				$retour2 = exec("perl script_perl/script_insertion_cnv.pl $iddossier $puce $chro $convertBaseB $convertBaseH $nbcopie $log2ratio $GenomeConvert $sondedebut $sondefin $verifie $methodeverification $herite \"$commentaire\" $classification ".substr($retour, 1)." ; echo $?");
			}else{
				$retour2 = exec("perl script_perl/script_insertion_cnv.pl $iddossier $puce $chro $convertBaseB $convertBaseH $nbcopie $log2ratio $GenomeConvert $sondedebut $sondefin $verifie $methodeverification $herite \"$commentaire\" $classification -1 ; echo $?");
				$retour = exec("perl script_perl/script_insertion_cnv.pl $iddossier $puce $chro $baseB $baseH $nbcopie $log2ratio $Genome $sondedebut $sondefin $verifie $methodeverification $herite \"$commentaire\" $classification ".substr($retour2, 1)." ; echo $?");
			}
		}

		else{
			$message .= "la localisation du CNV ne peut pas être correcte";
		}

		if (isset($retour)){
			$existe = substr($retour, 0, 1);
			$IdAno = substr($retour, 1);
			$existe2 = substr($retour2, 0, 1);
			$IdAno2 = substr($retour2, 1);
			$IdAno = substr($IdAno, 0, -1);
			$IdAno2 = substr($IdAno2, 0, -1);

		}

		//echo $retour."lll".$retour2;
		///////////////////////////////////////////////////////////////////////////////////



		if(($existe==0)&&($existe2==0)){
			// le cnv existe
			//echo "CNV inséré/";
			$ctrl=0;

		}elseif(($existe==1)&&($existe2==1)){
			//le cnv existe et est deja associé au dossier
			//echo "CNV déjà inséré avec le nom $IdAno2 et associé au dossier N°$iddossier/";

			$ctrl=0;//permet de stocker le fait que la requête a abouti
		}elseif(($existe==2)&&($existe2==2)){
			//le cnv existe et est deja associé au patient
			//echo "CNV déjà inséré avec l'ID N°$IdAno2 et associé au dossier N°$iddossier";

		}else{
			$message .= "problème : insertion impossible... Merci de recommencer";

		}
			


		// Si le CNV n'est pas encore associé au patient
		if ((($existe==0)&&($existe2==0)) ||(($existe==1)&&($existe2==1))){
			//insertion dans la table cnv_du_genome
			//$requete = "INSERT INTO cnv_$Genome(idcnv, idpuce, positiondebut, positionfin, chromosome, sondedebut, sondefin, log2ratio, nbcopie ,verifie, methodeverification, herite, commentaire, classification, iddossier)
			//VALUES ($IdAno, $puce, $baseB, $baseH,$chro, $sondedebut, $sondefin, $log2ratio, $nbcopie , $verifie, $methodeverification, $herite, '$commentaire', $classification, $iddossier);";

			$requete = "INSERT INTO cnv_$Genome ( idcnv, idpuce, positiondebut, positionfin, chromosome, sondedebut, sondefin, log2ratio, nbcopie ,verifie, methodeverification, herite, commentaire, classification ) values ";
			$requete .= " ( :idcnv, :idpuce, :positiondebut, :positionfin, :chromosome, :sondedebut, :sondefin, :log2ratio, :nbcopie ,:verifie, :methodeverification, :herite, :commentaire, :classification)";
			$requette_preparee = $this->connexion->prepare($requete);
			$requette_preparee->bindValue(":idcnv" , $IdAno, PDO::PARAM_INT);
			$requette_preparee->bindValue(":idpuce" , $cnv->idpuce, PDO::PARAM_INT);
			$requette_preparee->bindValue(":positiondebut" , $cnv->positiondebut, PDO::PARAM_INT);
			$requette_preparee->bindValue(":positionfin" , $cnv->positionfin, PDO::PARAM_INT);
			$requette_preparee->bindValue(":chromosome" , $cnv->chromosome, PDO::PARAM_STR);
			if ($cnv->sondedebut == null){
				$requette_preparee->bindValue(":sondedebut" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee->bindValue(":sondedebut" , $cnv->sondedebut, PDO::PARAM_STR);
			}
			if ($cnv->sondefin == null){
				$requette_preparee->bindValue(":sondefin" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee->bindValue(":sondefin" , $cnv->sondefin, PDO::PARAM_STR);
			};
			if ($cnv->log2ratio == null){
				$requette_preparee->bindValue(":log2ratio" , "", PDO::PARAM_STR);
			} else {
				$requette_preparee->bindValue(":log2ratio" , $cnv->log2ratio, PDO::PARAM_STR);
			};
			if ($cnv->nbcopie == null){
				$requette_preparee->bindValue(":nbcopie" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee->bindValue(":nbcopie" , $cnv->nbcopie, PDO::PARAM_STR);
			}

			if ($cnv->verifie == null){
				$requette_preparee->bindValue(":verifie" , 1, PDO::PARAM_INT);
			} else {
				$requette_preparee->bindValue(":verifie" , $cnv->verifie, PDO::PARAM_INT);
			}
			if ($cnv->methodeverification == null){
				$requette_preparee->bindValue(":methodeverification" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee->bindValue(":methodeverification" , $cnv->methodeverification, PDO::PARAM_INT);
			}
			if ($cnv->herite == null){
				$requette_preparee->bindValue(":herite" , 1, PDO::PARAM_INT);
			} else {
				$requette_preparee->bindValue(":herite" , $cnv->herite, PDO::PARAM_INT);
			}
			if ($cnv->commentaire == null){
				$requette_preparee->bindValue(":commentaire" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee->bindValue(":commentaire" , $cnv->commentaire, PDO::PARAM_STR);
			}
			if ($cnv->classification == null){
				$requette_preparee->bindValue(":classification" , 1, PDO::PARAM_INT);
			} else {
				$requette_preparee->bindValue(":classification" , $cnv->classification, PDO::PARAM_INT);
			}
			$t = $requette_preparee->execute();
			if (!$t ){
				$taberr = $requette_preparee->errorInfo();
				$message .= "Erreur numéro :".$taberr[0]."(".$taberr[1]."):".$taberr[2];
			}

			//insertion dans la table cnv_converti
			//$requete2 = "INSERT INTO cnv_$GenomeConvert(idcnv, idpuce, positiondebut, positionfin, chromosome, sondedebut, sondefin, log2ratio, nbcopie ,verifie, methodeverification, herite, commentaire, classification, iddossier)
			//VALUES ($IdAno2, $puce, $convertBaseB, $convertBaseH,$chro, $sondedebut, $sondefin, $log2ratio, $nbcopie , $verifie, $methodeverification, $herite, '$commentaire', $classification, $iddossier);";

			$requete2 = "INSERT INTO cnv_$GenomeConvert ( idcnv, idpuce, positiondebut, positionfin, chromosome, sondedebut, sondefin, log2ratio, nbcopie ,verifie, methodeverification, herite, commentaire, classification ) values ";
			$requete2 .= " (:idcnv, :idpuce, :positiondebut, :positionfin, :chromosome, :sondedebut, :sondefin, :log2ratio, :nbcopie ,:verifie, :methodeverification, :herite, :commentaire, :classification)";
			$requette_preparee2 = $this->connexion->prepare($requete2);
			$requette_preparee2->bindValue(":idcnv" , $IdAno2, PDO::PARAM_INT);
			$requette_preparee2->bindValue(":idpuce" , $cnv->idpuce, PDO::PARAM_INT);
			$requette_preparee2->bindValue(":positiondebut" , $convertBaseB, PDO::PARAM_INT);
			$requette_preparee2->bindValue(":positionfin" , $convertBaseH, PDO::PARAM_INT);
			$requette_preparee2->bindValue(":chromosome" , $cnv->chromosome, PDO::PARAM_STR);
			if ($cnv->sondedebut == null){
				$requette_preparee2->bindValue(":sondedebut" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee2->bindValue(":sondedebut" , $cnv->sondedebut, PDO::PARAM_STR);
			}
			if ($cnv->sondefin == null){
				$requette_preparee2->bindValue(":sondefin" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee2->bindValue(":sondefin" , $cnv->sondefin, PDO::PARAM_STR);
			};
			if ($cnv->log2ratio == null){
				$requette_preparee2->bindValue(":log2ratio" , "", PDO::PARAM_STR);
			} else {
				$requette_preparee2->bindValue(":log2ratio" , $cnv->log2ratio, PDO::PARAM_STR);
			};
			if ($cnv->nbcopie == null){
				$requette_preparee2->bindValue(":nbcopie" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee2->bindValue(":nbcopie" , $cnv->nbcopie, PDO::PARAM_STR);
			}

			if ($cnv->verifie == null){
				$requette_preparee2->bindValue(":verifie" , 1, PDO::PARAM_INT);
			} else {
				$requette_preparee2->bindValue(":verifie" , $cnv->verifie, PDO::PARAM_INT);
			}
			if ($cnv->methodeverification == null){
				$requette_preparee2->bindValue(":methodeverification" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee2->bindValue(":methodeverification" , $cnv->methodeverification, PDO::PARAM_INT);
			}
			if ($cnv->herite == null){
				$requette_preparee2->bindValue(":herite" , 1, PDO::PARAM_INT);
			} else {
				$requette_preparee2->bindValue(":herite" , $cnv->herite, PDO::PARAM_INT);
			}
			if ($cnv->commentaire == null){
				$requette_preparee2->bindValue(":commentaire" , NULL, PDO::PARAM_NULL);
			} else {
				$requette_preparee2->bindValue(":commentaire" , $cnv->commentaire, PDO::PARAM_STR);
			}
			if ($cnv->classification == null){
				$requette_preparee2->bindValue(":classification" , 1, PDO::PARAM_INT);
			} else {
				$requette_preparee2->bindValue(":classification" , $cnv->classification, PDO::PARAM_INT);
			}
			$t2 = $requette_preparee2->execute();
				
			if (!$t2 ){
				$taberr2 = $requette_preparee2->errorInfo();
				$message .= "Erreur numéro :".$taberr2[0]."(".$taberr2[1]."):".$taberr2[2];
			}

			if ($t2 && $t && $message==""){
				$message = $IdAno2;
			}
		}else{
			if($ctrl==0){

				$message .= "problème : insertion impossible... Merci de recommencer";
			} else {
				$message = $IdAno2;
			}
		}
		////////////////////////////////////////////////////////////////////////
		return $message;
	}//ajouter_CNV

	public function modifier_cnv($cnv)
	{
		$message = $this->ajouter_cnv($cnv);
		$this->supprimer_cnv($cnv);
		return $message;
	}


	public function supprimer_cnv($cnv)
	{
		$message = null;
		$cnv1 = $cnv->idcnv;

		$id_cnv18 = "CNV_".$cnv1;
		$id_cnv19 = "CNV_".$cnv1."0";
		$ReqSuppCNV="SELECT id FROM base_hg.hg18_name where name like :id_cnv18";
		$ReqSuppCNV2="SELECT id FROM base_hg.hg19_name where name like :id_cnv19";
		$requette_prepareeCNV = $this->connexion_base_hg->prepare($ReqSuppCNV);
		$requette_prepareeCNV->bindValue(":id_cnv18" , $id_cnv18, PDO::PARAM_INT);

		$requette_prepareeCNV2 = $this->connexion_base_hg->prepare($ReqSuppCNV);
		$requette_prepareeCNV2->bindValue(":id_cnv19" , $id_cnv19, PDO::PARAM_INT);


		//echo $ReqSuppCNV;
		////////////////////////////////////////////////////////////////////////////////////////////////

		////////////////////////////////////////////////////////////////////////////////////////////////

		$puce = $cnv->idpuce;


		/////////////////////////////////////////////////////////////////////////////////////////////
		// Exécution des requêtes
		if (($requette_prepareeCNV->execute()) && ($requette_prepareeCNV2->execute())){
			$r = $requette_prepareeCNV->fetchAll();
			foreach ($r as $row){
				$id_cnv = $row['id'];
				//echo $id_cnv;
				$retour = exec("perl script_perl/script_suppression_CNV.pl hg18 $id_cnv");
				//<!-- 0006_10/01/2012 : début -->
				$ReqSuppLien="DELETE FROM bdacpa.cnv_hg18 WHERE idpuce = :idpuce and idcnv = :idcnv";
				//<!-- 0006_10/01/2012 : fin -->
				$requette_prepareeSuppLien = $this->connexion->prepare($ReqSuppLien);
				$requette_prepareeSuppLien->bindValue(":idpuce" , $puce, PDO::PARAM_INT);
				$requette_prepareeSuppLien->bindValue(":idcnv" , $puce, $id_cnv);
				$t = $requette_prepareeSuppLien2->execute();
			}
			$r2 = $requette_prepareeCNV2->fetchAll();
			foreach ($r2 as $row){
				$id_cnv = $row['id'];
				$retour = exec("perl script_perl/script_suppression_CNV.pl hg19 $id_cnv");
				//<!-- 0006_10/01/2012 : début -->
				$ReqSuppLien2 = "DELETE FROM bdacpa.cnv_hg19 WHERE idpuce = :idpuce and idcnv = :idcnv";
				//<!-- 0006_10/01/2012 : fin -->
				$requette_prepareeSuppLien2 = $this->connexion->prepare($ReqSuppLien2);
				$requette_prepareeSuppLien2->bindValue(":idpuce" , $puce, PDO::PARAM_INT);
				$requette_prepareeSuppLien2->bindValue(":idcnv" , $puce, $id_cnv);
				$t2 = $requette_prepareeSuppLien2->execute();
			}
			if ($t && $t2){
				$message = "Le CNV du dossier a été supprimé";
			}else {
				$message =  "Echec durant la suppression du CNV. Veuillez recommencer";
			}
		}

		else{
			$message =  "Echec durant la suppression du CNV. Veuillez recommencer";

		}
		return $message;
	}


	function convert_log2R_nb_copie($log2ratio,$chromosome, $sexe){
		//A faire valider!!!!
		$seuil_0 = -4;
		$seuil_1 = -0.25;
		$seuil_2 = 0.25;
		$seuil_3 = 0.75;
		if ((($sexe == "F" || $sexe == "I") && $chromosome != 'y' && $chromosome != 'Y') || ($sexe == "M" && $chromosome != 'X' && $chromosome != 'x' && $chromosome != 'y' && $chromosome != 'Y')){
			if ($log2ratio < $seuil_0){
				$nb_copie = 0;
			} else if ($log2ratio >= $seuil_0 && $log2ratio < $seuil_1){
				$nb_copie = 1;
			}else if ($log2ratio >= $seuil_1 && $log2ratio < $seuil_2){
				$nb_copie = 2;
			}else if ($log2ratio >= $seuil_2 && $log2ratio < $seuil_3){
				$nb_copie = 3;
			}else if ($log2ratio >= $seuil_3 ){
				$nb_copie = 4;
			}
		} else
			if (($sexe == "F" ||$sexe == "I" ) && ($chromosome == 'y' || $chromosome == 'Y')){
			if ($log2ratio > 0){
				$nb_copie = 1;
			} else {
				$nb_copie = 0;
			}
		} else if ($sexe == "M" && ($chromosome == 'X' || $chromosome != 'x' || $chromosome != 'y' || $chromosome != 'Y')){
			if ($log2ratio < $seuil_0){
				$nb_copie = 0;
			}else if ($log2ratio >= -0.25 && $log2ratio < 0.25){
				$nb_copie = 1;
			}else if ($log2ratio >= 0.25 && $log2ratio < 0.80){
				$nb_copie = 2;
			}else if ($log2ratio >= 0.80 ){
				$nb_copie = 3;
			}
		}

		return $nb_copie;
	}

} // CNVDAO



?>
